#include <glib.h>

#include <string.h>

#include "reader.h"
#include "writer.h"
#include "crc.h"

gint
main (gint argc, gchar ** argv)
{
	GList * file  = NULL;
	GList * file2 = NULL;
	GList * file3 = NULL;
	GList * file4 = NULL;
	gboolean is_correct_crc = TRUE;

	g_printf ("Carregando o arquivo: iostat.pdf\n");
	(void) load_file ("iostat.pdf", &file, FALSE);

	g_printf ("Calculando CRC\n");	
	add_crc (file);

	g_printf ("Gravando o arquivo: iostat.crc.pdf\n");
	(void) write_file (file, "iostat.crc.pdf", TRUE);
	
	g_printf ("Carregando o arquivo: iostat.crc.pdf\n");
	(void) load_file ("iostat.crc.pdf", &file2, TRUE);

	g_printf ("Checando CRC: ");
	is_correct_crc = check_crc (file2);

	if (is_correct_crc)
		g_printf ("CORRETO\n");
	else
		g_printf ("INCORRETO\n");

	g_printf ("Embaralhando o arquivo: iostat.crc.pdf\n");	
	(void) shuffle (file2);	

	g_printf ("Gravando o arquivo iostat.crc.shuffle.pdf\n");
	(void) write_file (file2, "iostat.crc.shuffle.pdf", TRUE);


	g_printf ("Carregando o arquivo: iostat.crc.shuffle.pdf\n");
	(void) load_file ("iostat.crc.shuffle.pdf", &file3, TRUE);

	g_printf ("Checando CRC: ");
	is_correct_crc = check_crc (file3);

	if (!is_correct_crc)
		g_printf ("CORRETO\n");
	else
		g_printf ("INCORRETO\n");
	
	(void) load_file ("iostat.pdf", &file4, FALSE);
	
	g_printf ("Gravando o arquivo iostat.original.pdf\n");
	(void) write_file (file4, "iostat.original.pdf", FALSE);
	
	return 0;
}
